/**
 * 
 */
package net.xfok.ui.text;

import java.io.IOException;
import java.io.InputStream;

import net.xfok.ui.R;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author howard
 *
 */
public class XTextView extends Activity{
	private static final String TAG="XTextView";
	private XLogText xlog;
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xtext);  
        TextView t6 = (TextView) findViewById(R.id.xtext6);
        t6.setMovementMethod(LinkMovementMethod.getInstance());
        
        TextView t7 = (TextView) findViewById(R.id.xtext7);
        t7.setText(
            Html.fromHtml(
                "<b>text3:</b>  Text with a " +
                "<a href=\"http://www.xfok.net\">link</a> " +
                "created in the Java source code using HTML."));
        t7.setMovementMethod(LinkMovementMethod.getInstance());
        SpannableString ss = new SpannableString(
            "text4: Click here to dial the phone.");
        ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
                   Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
                   Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        
        TextView t8 = (TextView) findViewById(R.id.xtext8);
        t8.setText(ss);
        t8.setMovementMethod(LinkMovementMethod.getInstance());
        xlog=(XLogText)findViewById(R.id.xlog);
        Button xbt=(Button)findViewById(R.id.xtext_bt);
        xbt.setOnClickListener(new View.OnClickListener() {		
			public void onClick(View v) {
				// TODO Auto-generated method stub
				addLog();
			}
		});
        try {
            InputStream is = getAssets().open("asset.txt");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            String text = new String(buffer);
            TextView t10 = (TextView)findViewById(R.id.xtext10);
            t10.setText(text);
        } catch (IOException e) {
            // Should never happen!
            throw new RuntimeException(e);
        }
    }
	private void addLog(){	
		xlog.append(getResources().getString(R.string.xlog));
	}
}
